/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tbgb.gesturehandle.touch;

import com.nokia.mid.ui.multipointtouch.MultipointTouch;
import com.nokia.mid.ui.multipointtouch.MultipointTouchListener;
import java.util.Hashtable;
import tbgb.utils.collection.TracedHashtable;

/**
 *
 * @author LưuQuang
 */
public class TouchController implements MultipointTouchListener{
    public static final int MAX_TOUCHES = MultipointTouch.getMaxPointers();
    
    TracedHashtable touches = new TracedHashtable();
    
    public void pointersChanged(int[] touchIDs)
    {
        this.touches.beginTrace();
        for (int i = 0; i < touchIDs.length; ++i)
        {
            Integer touchID = new Integer(touchIDs[i]);
            if (this.touches.containsKey(touchID))
            {
                Object touchObject = this.touches.getAndMarkTraced(touchID);
                if (touchObject instanceof TBTouch)
                {
                    TBTouch touch = (TBTouch) touchObject;
                    touch.updateLocation();
                }
            }
            else
            {
                this.touches.put(touchID, new TBTouch(touchID.intValue()));
            }
        }

        this.touches.endTrace();
    }
    
    public Hashtable getTouches()
    {
        return this.touches;
    }
}
